﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MNNUTEM
{
    public partial class Proveedor : Form
    {
        private crudProveedor cProveedor;
        int rut;
        public Proveedor()
        {
            InitializeComponent();
            cProveedor = new crudProveedor();
        }

        private void updateGridView()
        {
            dataGridView1.DataSource = cProveedor.Consultation("select *from Proveedor");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            cProveedor.Insert(textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7);
            updateGridView();
        }

        private void Proveedor_Load(object sender, EventArgs e)
        {
            button4.Enabled = false;
            button3.Enabled = false; updateGridView();
           
        }

        private void getdatos()
        {
            DataSet DS;
            DS = cProveedor.Consultation2("select *from Proveedor where rutProveedor='" + rut+ "'");
            textBox1.Text = DS.Tables[0].Rows[0][1].ToString();
            textBox2.Text = DS.Tables[0].Rows[0][2].ToString();
            textBox3.Text = DS.Tables[0].Rows[0][3].ToString();
            textBox4.Text = DS.Tables[0].Rows[0][4].ToString();
            textBox5.Text = DS.Tables[0].Rows[0][5].ToString();
            textBox6.Text = DS.Tables[0].Rows[0][6].ToString();
            textBox7.Text = DS.Tables[0].Rows[0][7].ToString();
           

        }

        private void dataGridView1_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            rut = int.Parse(dataGridView1[1, e.RowIndex].Value.ToString());
            getdatos();
            button1.Enabled = false;
            button3.Enabled = true;
            button4.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            cProveedor.Delete(rut);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            cProveedor.Set(textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, rut);
            updateGridView();
        }
    }
}
